/*
A demonstration of break and continue, 
which also uses a function with a parameter.

Ray Ontko  1999/09/30
*/

#include <stdio.h>

int get_first_char() ;
int my_func( int n ) ;

main()
{
int c ;
int i ;

i = 0 ;
while( 1 )
  {
  i++ ;
  printf( "%d Enter n)ext, s)kip, or q)uit.\n" , i ) ;
  c = get_first_char() ;
  if ( c == 'q' )
    break ;
  if ( c == 's' )
    continue ;
  printf( "     f(%d) = %d\n" , i , my_func(i) ) ;
  } 
printf( "Thank you!\n" );
}

/*
int my_func( int n )

A simple function which receives an integer value 
as a parameter, and returns a computed value.

For positive values given, the return value
is the sum of all counting numbers up to and
including the given number.
*/
int my_func( int n )
{
int f ;

f = n * ( n + 1 ) / 2 ;

return f ;
}

/*
int get_first_char()

Returns the first character on a line, and
skips all other characters to the end of line
or end of file, whichever comes first.  If the
first character IS an end of line or end of
file, then THAT character is returned and
no skipping occurs.
*/
int get_first_char()
{
int first ;
int c ;

first = c = getchar() ;
while ( ( c != '\n' ) && ( c != EOF ) )
  c = getchar() ;

return first ;
}
