need help converting while loops to for loops in my code

This is a discussion on need help converting while loops to for loops in my code within the C Programming forums, part of the General Programming Boards category; Hello everyone, I'm new to learning C language and was wondering if anyone with more experiance could help me out.
...

need help converting while loops to for loops in my code

Hello everyone, I'm new to learning C language and was wondering if anyone with more experiance could help me out.
I only have about 20 hours at most of self learned C programming under my belt so bare with my stuff here.
Once I realized I knew enough to toss together a simple program that actully does somthing other then say "blah blah blah" i made a pound/kilogram converter, anyway the point of my post is I used while loop statments in my code and shortly after started learning about for loop statments, I thought I understood how to change my while loops to for loops but apparently I don't, when I change it to use for loops enstead of while loops when i run my program and select 2 it goes to convert pounds to kilograms although it should be converting kilograms to pounds like it does when I use the while loops.
Anyway heres my code and how I thought I was supposed to change it and my question is at the bottom

but neither of these two codes work like the first one as explained earlier

Can someone please help me convert the while loop staments in the top piece of code to for loop statments, any help would be very very appreciated.

Also I have another small piece of code I'm trying to convert from for loops to while loops to help me better understand the concept of for looping but after I make the changes the results are not what I'm expecting, if anyone could help me convert this piece of code the same way as I need the other one converted (but opposite) it would be very very appreciated.

While loops are repeated as long as the condition of entry is true ...
For loops iterate through a set of values while the repeat condition is true.
They have very different applications and often you can't replace one with another.

In your first piece of code the exit condition is entering a number 3 or greater.
You can't really replace that with a for loop since you aren't iterating through any given number of values. A better replacement in your first piece of code would be to replace the while conditions with if statements...

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

You can use any loop in place of any other, but in my opinion, you should use whatever loop makes your code the most readable.

Code:

for( x = 0; x < 10; x++ )
{
...do something 10 times...
}

That's clear and readable, and I would probably use that more than I would to write it this way:

Code:

x = 0;
while( x < 10 )
{
...do something...
x++;
}

Or even:

Code:

x = 0;
do
{
...
x++;
}
while( x < 10 );

Some of it is just cleaner.

Now what if I was doing a menu?

Code:

do
{
showmenu();
c = getchoice();
} while( ! validchoice( c ) );

Could I do that with a for loop? Sure.

Code:

for( ; ; ! validchoice( c ) )
{
showmenu();
c = getchoice();
}

Does it look better? Not to me. Also, there are some very subtle differences here.

For one, a do-while will always execute at least once. So you need to consider that when you make loops. Do you always need it to work at least once? Then do-while is probably what you want. Do you need to test and maybe loop? Then either a while or a for is probably best. Can you use a do-while for something you need to check to see if you need to loop before actually looping? Sure, it's just more involved, and looks a bit messy: