Pseudocode For Loop

Hi guys, I am looking to write one of my for loops in pseudocode but I cannot find anything on the internet that I can understand so I am hoping someone can help.

I know for the cout << "\n\n\t" << x << " : "; I can do Print X and " : ", it is just the for loop.

Thanks.

1
2
3
4
5
  for (x=1; x<=noofsp; x++)
	{ 
		 cout << "\n\n\t" << x << " : ";
		 cin >> name;
        }
Does this help at all? There's an example of expressing a for loop near the top.
http://users.csc.calpoly.edu/~jdalbey/SWE/pdl_std.html

FOR all the characters in the name (good)
FOR character = first to last (ok)


(Note: You don't need to follow psuedocode standardization religiously unless told you, so this is just a guideline. :D)

-Albatross
Last edited on
generally for loops look like this

1
2
3
4
for( int i = 0; i < SIZE; ++i )
{
    //stuff to repeat SIZE times.
}


*edit

Oh forgot the pseudo half:

1
2
3
4
for( assign initial values; condition; increment )
{
    //stuff to repeat
}
Last edited on
Hi Albatross, I don't see how I can apply that example to mine, in this case I do need to apply to it so that it can be easily understood. Giglit I know what for loops look like, I am looking to convert my code into an algorithm e.g.

If studentgrade >= 60
Print "Passed"
else
Print "Failed"
endif

Last edited on
then you would have to throw those if/else inside of your for loop

1
2
3
4
5
6
7
8

for( int i = 0; i < size; ++i )
{
    if( studentgrade[i] >= 60 )
        cout << "Passed" << endl;
    else
        cout << "Failed" << endl;
}
I don't think you understand what I am trying to ask giblit, the code that I placed at the beginning of the question was:

for (x=1; x<=noofsp; x++)
{
cout << "\n\n\t" << x << " : ";
cin >> name;
}


In which case I know I have to put:

Print x and " : "

for the

If studentgrade >= 60
Print "Passed"
else
Print "Failed"
endif

I was just reffering to an example of pseudocode that I know for an IF STATEMENT, I just do not know how to do pseudocode for a FOR LOOP.
Last edited on
giblit I am looking at ur edited reply now
Perhaps something like this:

1
2
3
4
5
Function print results - input: array studentgrade[]

    For each grade in array studentgrade[]

         If ....

or
1
2
3
4
5
6
7
Function print results - input: array studentgrade[] of size n

    For each i in [ 0, n-1 )

         let grade <- studentgrade[i]

         If ...

Thanks everybody. Sorted now.
Topic archived. No new replies allowed.