Sponsored Content
Full Discussion: While loop problem in C
Top Forums Programming While loop problem in C Post 302726287 by gabam on Sunday 4th of November 2012 03:51:23 AM
Old 11-04-2012
While loop problem in C

Hello friends,
Please have a look at this code, and then i will tell you the problem.

Code:
 
int main()
{
    int i = 0;
    int cont = 1;
 
    while( cont == 1 ) 
    {
             printf( "Enter i\n" );
             scanf( "%d", &i );
 
             switch( i )
             {
                    case 1:
                              printf( "1\n" );
                              cont = 0;
                              break;
                    case 2:
                              printf( "2\n" );
                              cont = 0;
                              break;
                    default:
                              printf( "Invalid value" );
             }
    }
 
    return 0;
}

Here is the problem. The condition for while loop is true initially, so it's body is executed. But when the default case for switch executes, control returns to while, and while the condition is true, the body of while does not execute, and the program does not terminate. What could be the problem?

Thanks in advance!
 

10 More Discussions You Might Find Interesting

1. Programming

problem with while loop

hi all, i have written the following code: while(proceed !='Y' && proceed!='N' && proceed!='y' && proceed!='n') { printf("\nPress \n\t 'Y' or 'y' to continue \n\t 'N' or 'n' to cancel:"); scanf("%c",&proceed); } the output i am gettin is: Press 'Y' to continue ... (1 Reply)
Discussion started by: mridula
1 Replies

2. Shell Programming and Scripting

for loop problem

Hi, I have a directory called logs in which i have the log files. i have to touch the file before deleting it. i am doing like this filestodelete="*.log* *log*" for files in $filestodelete do touch $files $files.$(date +%a) rm -f $filestodelete done touch is not working... (5 Replies)
Discussion started by: namishtiwari
5 Replies

3. UNIX for Advanced & Expert Users

loop problem

Hi guys my while do loop is not working properly; As soon as the load_date and run_date is same it should stop can somebody tell me where I am having the problem? In an oracle table I have LOAD_DT=5/1/2009 DATE datatype RUN_DT=5/5/2009 DATE datatype Now in a script with a spool file I get the... (15 Replies)
Discussion started by: henrysmith
15 Replies

4. Shell Programming and Scripting

Problem in While loop

Hi Guys, This is my code.. I am getting an error in the inside while statement when comparing.. I am not able to figure it out.. Pls help me... while read value fatherid son_id top_id r_type do inside_value=1; echo $inside_value; echo $r_type; while do echo... (6 Replies)
Discussion started by: mac4rfree
6 Replies

5. Shell Programming and Scripting

problem with while loop

hi I had created a while loop in a script file called whiletest.sh as follows as follows: count=0 max=10 while do echo $count echo count=$(count+1)" " done echo "value of count:$count" then i run the script with the command sh whilestest.sh but its giving me an error... (5 Replies)
Discussion started by: angel12345
5 Replies

6. UNIX for Dummies Questions & Answers

While loop problem

I have a while loop with -f and -o option.Can any one please tell me what that stands for?The Sample code is as follows:- while do ## some processing done (10 Replies)
Discussion started by: Param0073
10 Replies

7. Shell Programming and Scripting

Problem with While loop.

Hi Script Gurus, I am facing issue with while loop in bash. The while loop is running as end less loop even after given criteria does not meet. STATE_BEFORE_SPLIT () { for clone in $Clonegroups; do state=$( $Navicmd -listclone -name $clone -cloneid $Cloneid |awk... (3 Replies)
Discussion started by: RobP
3 Replies

8. Shell Programming and Scripting

Problem with loop within loop

Hi, I work on Ab-initio ETL tool which is based on Unix. I made a small script which has two loop's one with in another. All the functionality is working for the first line of outer loop but when it comes to other lines of outer loop it is throwing error as command not found. Below is the... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

9. Shell Programming and Scripting

Problem with While Do loop

I am trying to do a while do loop that asks for a password and returns if the password entered is incorrect. I have that part working however i want to modify it so that if a similar word is entered it will read "that is close but incorrect" and i cannot seem to get it working, being new in the... (6 Replies)
Discussion started by: lm5522
6 Replies

10. Shell Programming and Scripting

Problem with loop

Hi all, a problem with a loop. Imagine it starts with var1="$(cat txtif.out )"while do echo file1 echo file2 echo y > txtif.out if then break fi done exit 0 the problem is that if the file is changing during the loop seems to continue as it reads "x" state,... (5 Replies)
Discussion started by: Board27
5 Replies
Layout::Manager(3pm)					User Contributed Perl Documentation				      Layout::Manager(3pm)

NAME
Layout::Manager - 2D Layout Management SYNOPSIS
Layout::Manager provides a simple interface for creating layout managers, or classes that size and position components within a container. A few managers are provided for reference, but this module is primarily meant to serve as a base for outside implementations. use Layout::Manager; my $foo = Layout::Manager->new; $foo->do_layout($component); USING A LAYOUT MANAGER
Layout::Manager relies on Graphics::Primitive::Container as a source for it's components. Various implementations of Layout::Manager will require you do add components with slightly different second arguments, but the general case will be: $lm->add_component($comp, $constraints); The contents of $constraints must be discerned by reading the documentation for the layout manager you are using. The $comp argument must be a Graphics::Primitive::Component. Layout manager works hand-in-hand with Graphics::Primitive, so you'll want to check out the lifecyle documented in Graphics::Primitive::Component. It will look something like this: $cont->add_component($foo, { some => metadata }); $driver->prepare($cont); my $lm = new Layout::Manager::SomeImplementation; $lm->do_layout($cont); $driver->pack($cont); $driver->draw($cont); When you are ready to lay out your container, you'll need to call the do_layout method with a single argument: the component in which you are laying things out. When do_layout returns all of the components should be resized and repositioned according to the rules of the Layout::Manager implementation. PREPARATION Subsequent calls to do_layout will be ignored if the Container is prepared. The Container's "prepared" flag and the flags of all it's children are checked, so any modifications to any child component will cause the entire container (and any container children) to be laid out again. WRITING A LAYOUT MANAGER
Layout::Manager provides all the methods necessary for your implementation, save the do_layout method. This method will be called when it is time to layout the components. The add_component method takes two arguments: the component and a second, abritrary piece of data. If your layout manager is simple, like Compass, you may only require a simple variable like "NORTH". If you create something more complex the second argument may be a hashref or an object. The value of the components method is an arrayref of hashrefs. The hashrefs have two keys: component The component to be laid out. args The argument provided to add_component. TIPS
Layout manager implementations should honor the visible attribute of a component, as those components need to be ignored. METHODS
do_layout Lays out this manager's components in the specified container. AUTHOR
Cory Watson, "<gphat@cpan.org>" SEE ALSO
perl(1), Graphics::Primitive COPYRIGHT &; LICENSE Copyright 2008 - 2010 Cory G Watson This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.3 2011-05-16 Layout::Manager(3pm)
All times are GMT -4. The time now is 09:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy