I have probem / strange question, i got algorithm with few "for" loops and now i need to do block scheme of this algorithm.
I know how to picture "while" loop, but is this acceptable to represent "for" loop using "while" and at this point make difference between souce code and algorithm?. Ofcourse assuming that all "for" loops are right in place and using loop of any other kind would produce unnecessary code which i avoided using "for" loops.
I'm guessing that this is rather impossible (at least I can't imagine this) to simply picture "for" loop, but maybe there is a way (if exists).
Thanks in advance
C For Loop Syntax. The for loop's triad statement is like the ( i=0 ; i < n ; i++ ). First comes the initialization of the counter variable. For example – If the variable is “i” then it needs to be initialized like the following.
Here again, a hexagon shaped flowchart symbol is used to represent the for loop and the symbol is divided into three to represent the initial condition, the increment, and the terminating condition.
Using For Loops Say we wanted to loop through a block of code 5 times, we use i, a local variable, that is built into most programming languages, and can be used in pseudocode too. We would say: For i = 1 To 5; 5 being the number of times you want to loop the code; you can change this to what you would like.
Here's a flow chart that illustrates a for loop:
The equivalent C code would be
for(i = 2; i <= 6; i = i + 2) { printf("%d\t", i + 1); }
I found this and several other examples on one of Tenouk's C Laboratory practice worksheets.
What's a "block scheme"?
If I were drawing it, I might draw a box with "for each x in y" written in it.
If you're drawing a flowchart, there's always a loop with a decision box.
Nassi-Schneiderman diagrams have a loop construct you could use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With