The Gateway to Computer Science Excellence
+2 votes
354 views

Consider the two program segments below:

  1. for
        i:=1 to f(x) by 1 do
        S
    end
  2. i:=1;
    While   i<=f(x) do
            S
            i:=i+1
    end
    

Under what conditions are these two programs equivalent? Treat $S$ as any sequence of statement and f as a function.

in Programming by Veteran (105k points) | 354 views

1 Answer

0 votes
In both program segment if f(x) returns same value
by Active (3.2k points)
0
What is the meaning of

for i:=1 to f(x) by1do

Does this mean i=1 to i<f(x)
0
It means:  i=1 to i$\leq$f(x)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,647 questions
56,492 answers
195,438 comments
100,676 users