The Gateway to Computer Science Excellence
+3 votes
532 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 | 532 views

1 Answer

+1 vote
In both program segment if f(x) returns same value
by
+1
What is the meaning of

for i:=1 to f(x) by1do

Does this mean i=1 to i<f(x)
+1
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
52,315 questions
60,438 answers
201,786 comments
95,270 users