SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
Object-Oriented Programming Language
                                Chapter 6 : Making Decisions


                          Atit Patumvan
          Faculty of Management and Information Sciences
                        Naresuan University
2



                                                                                     Contents



             •        The if statement

             •        The switch statement

             •        The conditional operator




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University              Object-Oriented Programming Language
3



                                                                           The if Statement


                 if ( expression )
                    program_statement

                                                                                              [ expression ]   [ !expression ]


                                                                                     program_statement




                 if ( it is not raining )
                    i will go to swimming
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                                   Object-Oriented Programming Language
4



                                                                            The if Statement

Program 6.1
01: #import <Foundation/Foundation.h>
02:
03: int main(int argc, const char * argv[])
04: {
05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
06:
07:! int number;
08:
09:! NSLog(@"Type in your number: ");
10:! scanf("%i", &number);
11:
12:! if( number < 0 )
13: ! ! number = -number;
14:
15:! NSLog(@"The absolute value is %i", number);
16:
17:! [pool drain];                                 Type in your number:
18:! return 0;                                     -100
19: }                                              The absolute value is 100

                                                                                      Type in your number:
                                                                                      2000
                                                                                      The absolute value is 2000

Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                                 Object-Oriented Programming Language
5



                                                                           The if Statement


            -(double) convertToNum
            {
               return (double) numerator / denominator;
            }



             [ condition ]                                      [ ! condition ]


         process 1                                                           process 2
                                                                                         -(double) convertToNum
                                                                                         {
                                                                                            if (denominator != 0 )
                                                                                                return numerator / denominator;
                                                                                            else
                                                                                                return NAN;
                                                                                         }
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                                    Object-Oriented Programming Language
6



                                                                            The if Statement

Program 6.2
37: -(double) convertToNum
38: {
39:! if(denominator != 0)
40:! ! return (double) numerator/denominator;
41:! else
42:! ! return NAN;
43: }

51:!      Fraction * aFraction = [[Fraction alloc] init];
52:!      Fraction * bFraction = [[Fraction alloc] init];
53:!
54:!      [aFraction setNumerator: 1];! /1st fraction is 1/4
                                      /
55:!      [aFraction setDenominator: 4];
56:
57:!      [aFraction print];
58:!      NSLog(@" =");                                                                        1/4
59:!      NSLog(@" %g", [aFraction convertToNum]);                                             =
60:                                                                                            0.25
61:!      [bFraction print];! / never assigned a value
                            /                                                                  0/0
62:!      NSLog(@" =");                                                                        =
63:!      NSLog(@" %g", [bFraction convertToNum]);                                             nan
64:!      !
65:!      [aFraction release];
66:!      [bFraction release];

Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                    Object-Oriented Programming Language
7



                                                       Triangular Number Example

Program 6.3, Program 6.4
01: #import <Foundation/Foundation.h>
02:
03: int main(int argc, const char * argv[])
04: {
05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
06:
07:! int number_to_test, remainder;
08:
09:! NSLog(@"Enter your number to ne tested: ");
10:
11:! scanf("%i", &number_to_test);
12:
13:! remainder = number_to_test % 2;
14:
15:! if( remainder == 0 )
16: ! ! NSLog(@"The number is even.");                if( remainder == 0 )
17:                                                    ! ! NSLog(@"The number is even.");
18:! if( remainder != 0)                              ! else
19:! ! NSLog(@"The number is odd.");                  ! ! NSLog(@"The number is odd.");
20:
21:! [pool drain];
22:! return 0;
23: }


Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University   Object-Oriented Programming Language
8



                                                         Compound Relational Test


                             Logical Operator                                        Descriptions

                                            &&                                          AND

                                              ||                                         OR

                                               !                                        NOT



               if ( grade > 70 && grade <= 79 )
                  ++grades_70_to79;

               if ( index < 0 || index > 99 )
                  NSLog (@”Error - index out of range”);
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                  Object-Oriented Programming Language
9



                                                        Compound Relational Tests

Program 6.5
01: #import <Foundation/Foundation.h>
02:
03: int main(int argc, const char * argv[])
04: {
05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
06:
07:! int year, rem_4, rem_100, rem_400;
08:
09:! NSLog(@"Enter the year to be tested: ");
10:
11:! scanf("%i", &year);
12:
13:! rem_4 = year % 4;
14:! rem_100 = year % 100;
15:! rem_400 = year % 400;
16:
17:! if( (rem_4 == 0 && rem_100 != 0) || rem_400 == 0 )
18:! ! NSLog(@"It's a leap year.");
19:! else
20:! ! NSLog(@"Nope, It's not a leap year.");
21:
22:! [pool drain];
23:! return 0;
24: }

Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University   Object-Oriented Programming Language
10



                                                                   Nested if Statements


               if ( [chessGame isOver] == NO )
                  if ( [chessGame whoseTurn] == YOU )
                     [chessGame yourMove];

               if ( [chessGame isOver] == NO && [chessGame whoseTurn] == YOU )
                     [chessGame yourMove];




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University        Object-Oriented Programming Language
11



                                                                   Nested if Statements


               if ( [chessGame isOver] == NO )
                  if ( [chessGame whoseTurn] == YOU )
                     [chessGame yourMove];
                  else
                     [chessGame myMove];

               if ( [chessGame isOver] == NO )
                  if ( [chessGame whoseTurn] == YOU )
                     [chessGame yourMove];
                  else
                     [chessGame myMove];
               else
                  [chessGame finish];




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University        Object-Oriented Programming Language
12



                                                                                Dangling Else


            if ( [chessGame isOver] == NO )                                              if ( [chessGame isOver] == NO )
               if ( [chessGame whoseTurn] == YOU )                                          if ( [chessGame whoseTurn] == YOU )
                  [chessGame yourMove];                                                        [chessGame yourMove];
            else                                                                            else
               [chessGame finish];                                                              [chessGame finish];



                if ( [chessGame isOver] == NO ) {
                   if ( [chessGame whoseTurn] == YOU )
                      [chessGame yourMove];
                }
                else
                   [chessGame finish];




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                                 Object-Oriented Programming Language
13



                                                                   The else if Construct




                if ( expression_1 )
                                                                                     if ( expression_1 )
                   program_statement_1
                                                                                        program_statement_1
                else
                                                                                     else if ( expression_2 )
                  if ( expression_2 )
                                                                                        program_statement_2
                     program_statement_2
                                                                                     else
                  else
                                                                                        program_statement_3
                     program_statement_3




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                         Object-Oriented Programming Language
14



                                                                    The else if Construct

Program 6.6
01: #import <Foundation/Foundation.h>
02:
03: int main(int argc, const char * argv[])
04:{
05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
06:
07:! int number, sign;
08:
09:! NSLog(@"Please type in a number: ");
10:! scanf("%i", &number);
11:
12:! if (number <0)
13:! ! sign = -1;
14:! else if ( number == 0 )
15:! ! sign = 0; // Must be positive
16:! else
17:! ! sign = 1;
18:!
19:! NSLog(@"Sign = %i", sign);
20:
21:! [pool drain];
22:! return 0;
23:


Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University          Object-Oriented Programming Language
15



                                                                    The else if Construct

Program 6.7

01: #import <Foundation/Foundation.h>
02:
03: int main(int argc, const char * argv[])
04: {
05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
06:
07:! char c;
08:
09:! NSLog(@"Enter a single character: ");
10:! scanf(" %c", &c);
11:
12:! if (( c>= 'a' && c<='z') || (c>='A' && c<='Z'))
13:! ! NSLog(@"It's a alphabetic character.");
14:! else if (c >='0' && c<='9')
15:! ! NSLog(@"It's a digit.");
16:! else
17:! ! NSLog(@"It's a special character.");
18:
19:! [pool drain];
20:! return 0;
21: }



Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University          Object-Oriented Programming Language
16



                                                                    The else if Construct

Program 6.8, Program 6.8A
01: int main(int argc, const char * argv[])
02: {
03:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
04:! double! value1, value2;
05:! char! ! operator;
06:! Calculator * deskCalc = [[Calculator alloc] init];
07:! NSLog(@"Type in your expression. ");
08:! scanf("%lf %c %lf", &value1, & operator, &value2);
09:
10:! [deskCalc setAccumulator: value1];
11:! if (operator == '+')                       11:! ! if (operator == '+')
12:! ! [deskCalc add: value2];                  12:! ! ! [deskCalc add: value2];
13:! else if (operator == '-')                  13:! ! else if (operator == '-')
14:! ! [deskCalc subtract: value2];             14:! ! ! [deskCalc subtract: value2];
15:! else if (operator == '*')                  15:! ! else if (operator == '*')
16:! ! [deskCalc multiply: value2];             16:! ! ! [deskCalc multiply: value2];
17:! else if (operator == '/')                  17:! ! else if (operator == '/')
18:! ! [deskCalc divide: value2];               18:! ! ! if( value2 == 0)
19:!                                            19:! ! ! ! NSLog(@"Division by zero.");
20:! NSLog(@"%.2f", [deskCalc accumulator]);    20:! ! ! else!
21:                                             21:! ! ! ! [deskCalc divide: value2];
22:! [deskCalc release];                        22:! ! else
23:! [pool drain];                              23:! ! ! NSLog(@"Unknown operator.");
24:! return 0;
25: }
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University          Object-Oriented Programming Language
17



                                                                  The switch Statement


                 if ( expression == value1)
                                                                                     switch ( expression )
                 {
                                                                                     {
                       program statement;
                                                                                       case value1:
                       program statement;
                                                                                         program statement;
                        …
                                                                                         program statement;
                 }
                                                                                          …
                 else if ( expression == value2)
                                                                                         break;
                 {
                                                                                       case value2:
                       program statement;
                                                                                         program statement;
                       program statement;
                                                                                         program statement;
                        …
                                                                                          …
                 }
                                                                                         break;
                 else if ( expression == value3)
                                                                                       case value3:
                 {
                                                                                         program statement;
                       program statement;
                                                                                         program statement;
                       program statement;
                                                                                          …
                        …
                                                                                         break;
                 }
                                                                                       default:
                 else
                                                                                         program statement;
                 {
                                                                                         program statement;
                       program statement;
                                                                                          …
                       program statement;
                                                                                         break;
                        …
                                                                                     }
                 }


Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                            Object-Oriented Programming Language
18



                                                                    The else if Construct

Program 6.8, Program 6.9
03:!      NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
04:!      double! value1, value2;
05:!      char! ! operator;
06:!      Calculator * deskCalc = [[Calculator alloc] init];
07:!      NSLog(@"Type in your expression. ");
08:!      scanf("%lf %c %lf", &value1, & operator, &value2);
09:
10:!      ! if (operator == '+')                                                     10:!   !   switch (operator) {
11:!      ! ! [deskCalc add: value2];                                                11:!   !   ! ! case '+':
12:!      ! else if (operator == '-')                                                12:!   !   ! ! ! [deskCalc add: value2];
13:!      ! ! [deskCalc subtract: value2];                                           13:!   !   ! ! ! break;
14:!      ! else if (operator == '*')                                                14:!   !   ! ! case '-':
15:!      ! ! [deskCalc multiply: value2];                                           15:!   !   ! ! ! [deskCalc subtract: value2];
16:!      ! else if (operator == '/')                                                16:!   !   ! ! ! break;
17:!      ! ! if( value2 == 0)                                                       17:!   !   ! ! case '*':
18:!      ! ! ! NSLog(@"Division by zero.");                                         18:!   !   ! ! ! [deskCalc multiply: value2];
19:!      ! ! else!                                                                  19:!   !   ! ! ! break;
20:!      ! ! ! [deskCalc divide: value2];                                           20:!   !   ! ! case '/':
21:!      ! else                                                                     21:!   !   ! ! ! [deskCalc divide: value2];
22:!      ! ! NSLog(@"Unknown operator.");!                                          22:!   !   ! ! ! break;
23:!      NSLog(@"%.2f", [deskCalc accumulator]);                                    23:!   !   ! ! default:
24:                                                                                  24:!   !   ! ! ! NSLog(@"Unknown operator.");
25:!      [deskCalc release];                                                        25:!   !   ! }
26:!      [pool drain];
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                                    Object-Oriented Programming Language
19



                                                                           Boolean Variable

Program 6.10, Program 6.10A
01: #import <Foundation/Foundation.h>
02:
03: int main(int argc, const char * argv[])
04: {
05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
06:
07:! int p, d, isPrime;
08:!
09:! for (p =2; p<=50; ++p){                    08:! BOOL isPrime;
10:! ! isPrime =1;                              09:! !
11:! !                                          10:! ! for (p =2; p<=50; ++p){
12:! ! for ( d = 2; d < p; ++d)                 11:! ! ! isPrime = YES;
13:! ! ! if ( p % d == 0)                       12:! ! !
14:! ! ! ! isPrime = 0;                         13:! ! ! for ( d = 2; d < p; ++d)
15:! ! ! !                                      14:! ! ! ! if ( p % d == 0)
16:! ! if( isPrime != 0 )                       15:! ! ! ! ! isPrime = NO;
17:! ! ! NSLog(@"%i ", p);                      16:! ! ! ! !
18:! }                                          17:! ! ! if( isPrime == YES )
19:!                                            18:! ! ! ! NSLog(@"%i ", p);
20:! [pool drain];                              19:! ! }
21:! return 0;
22: }


Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University            Object-Oriented Programming Language

Más contenido relacionado

Destacado

Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)Atit Patumvan
 
Chapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computationChapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computationAtit Patumvan
 
An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)Atit Patumvan
 
คณิตศาสตร์คืออะไร
คณิตศาสตร์คืออะไรคณิตศาสตร์คืออะไร
คณิตศาสตร์คืออะไรJiraprapa Suwannajak
 
How to Study and Research in Computer-related Master Program
How to Study and Research in Computer-related Master ProgramHow to Study and Research in Computer-related Master Program
How to Study and Research in Computer-related Master ProgramWongyos Keardsri
 

Destacado (6)

Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)
 
Chapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computationChapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computation
 
Pat1 set1
Pat1 set1Pat1 set1
Pat1 set1
 
An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)
 
คณิตศาสตร์คืออะไร
คณิตศาสตร์คืออะไรคณิตศาสตร์คืออะไร
คณิตศาสตร์คืออะไร
 
How to Study and Research in Computer-related Master Program
How to Study and Research in Computer-related Master ProgramHow to Study and Research in Computer-related Master Program
How to Study and Research in Computer-related Master Program
 

Más de Atit Patumvan

Iot for smart agriculture
Iot for smart agricultureIot for smart agriculture
Iot for smart agricultureAtit Patumvan
 
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ตแบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ตAtit Patumvan
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics toolsAtit Patumvan
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics toolsAtit Patumvan
 
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6Atit Patumvan
 
Computer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : MethodsComputer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : MethodsAtit Patumvan
 
Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops Atit Patumvan
 
Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2Atit Patumvan
 
Computer Programming: Chapter 1
Computer Programming: Chapter 1Computer Programming: Chapter 1
Computer Programming: Chapter 1Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 1
การบริหารเชิงคุณภาพ ชุดที่ 1การบริหารเชิงคุณภาพ ชุดที่ 1
การบริหารเชิงคุณภาพ ชุดที่ 1Atit Patumvan
 
Write native iPhone applications using Eclipse CDT
Write native iPhone applications using Eclipse CDTWrite native iPhone applications using Eclipse CDT
Write native iPhone applications using Eclipse CDTAtit Patumvan
 
OOP Chapter 8 : Inheritance
OOP Chapter 8 : InheritanceOOP Chapter 8 : Inheritance
OOP Chapter 8 : InheritanceAtit Patumvan
 

Más de Atit Patumvan (20)

Iot for smart agriculture
Iot for smart agricultureIot for smart agriculture
Iot for smart agriculture
 
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ตแบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics tools
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics tools
 
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
 
Media literacy
Media literacyMedia literacy
Media literacy
 
การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8
 
การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7
 
การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6
 
Computer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : MethodsComputer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : Methods
 
Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops
 
Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)
 
การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5
 
การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4
 
การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3
 
การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2
 
Computer Programming: Chapter 1
Computer Programming: Chapter 1Computer Programming: Chapter 1
Computer Programming: Chapter 1
 
การบริหารเชิงคุณภาพ ชุดที่ 1
การบริหารเชิงคุณภาพ ชุดที่ 1การบริหารเชิงคุณภาพ ชุดที่ 1
การบริหารเชิงคุณภาพ ชุดที่ 1
 
Write native iPhone applications using Eclipse CDT
Write native iPhone applications using Eclipse CDTWrite native iPhone applications using Eclipse CDT
Write native iPhone applications using Eclipse CDT
 
OOP Chapter 8 : Inheritance
OOP Chapter 8 : InheritanceOOP Chapter 8 : Inheritance
OOP Chapter 8 : Inheritance
 

Último

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Último (20)

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 

OOP Chapter 6: Making Decisions

  • 1. Object-Oriented Programming Language Chapter 6 : Making Decisions Atit Patumvan Faculty of Management and Information Sciences Naresuan University
  • 2. 2 Contents • The if statement • The switch statement • The conditional operator Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 3. 3 The if Statement if ( expression ) program_statement [ expression ] [ !expression ] program_statement if ( it is not raining ) i will go to swimming Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 4. 4 The if Statement Program 6.1 01: #import <Foundation/Foundation.h> 02: 03: int main(int argc, const char * argv[]) 04: { 05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 06: 07:! int number; 08: 09:! NSLog(@"Type in your number: "); 10:! scanf("%i", &number); 11: 12:! if( number < 0 ) 13: ! ! number = -number; 14: 15:! NSLog(@"The absolute value is %i", number); 16: 17:! [pool drain]; Type in your number: 18:! return 0; -100 19: } The absolute value is 100 Type in your number: 2000 The absolute value is 2000 Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 5. 5 The if Statement -(double) convertToNum { return (double) numerator / denominator; } [ condition ] [ ! condition ] process 1 process 2 -(double) convertToNum { if (denominator != 0 ) return numerator / denominator; else return NAN; } Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 6. 6 The if Statement Program 6.2 37: -(double) convertToNum 38: { 39:! if(denominator != 0) 40:! ! return (double) numerator/denominator; 41:! else 42:! ! return NAN; 43: } 51:! Fraction * aFraction = [[Fraction alloc] init]; 52:! Fraction * bFraction = [[Fraction alloc] init]; 53:! 54:! [aFraction setNumerator: 1];! /1st fraction is 1/4 / 55:! [aFraction setDenominator: 4]; 56: 57:! [aFraction print]; 58:! NSLog(@" ="); 1/4 59:! NSLog(@" %g", [aFraction convertToNum]); = 60: 0.25 61:! [bFraction print];! / never assigned a value / 0/0 62:! NSLog(@" ="); = 63:! NSLog(@" %g", [bFraction convertToNum]); nan 64:! ! 65:! [aFraction release]; 66:! [bFraction release]; Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 7. 7 Triangular Number Example Program 6.3, Program 6.4 01: #import <Foundation/Foundation.h> 02: 03: int main(int argc, const char * argv[]) 04: { 05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 06: 07:! int number_to_test, remainder; 08: 09:! NSLog(@"Enter your number to ne tested: "); 10: 11:! scanf("%i", &number_to_test); 12: 13:! remainder = number_to_test % 2; 14: 15:! if( remainder == 0 ) 16: ! ! NSLog(@"The number is even."); if( remainder == 0 ) 17: ! ! NSLog(@"The number is even."); 18:! if( remainder != 0) ! else 19:! ! NSLog(@"The number is odd."); ! ! NSLog(@"The number is odd."); 20: 21:! [pool drain]; 22:! return 0; 23: } Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 8. 8 Compound Relational Test Logical Operator Descriptions && AND || OR ! NOT if ( grade > 70 && grade <= 79 ) ++grades_70_to79; if ( index < 0 || index > 99 ) NSLog (@”Error - index out of range”); Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 9. 9 Compound Relational Tests Program 6.5 01: #import <Foundation/Foundation.h> 02: 03: int main(int argc, const char * argv[]) 04: { 05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 06: 07:! int year, rem_4, rem_100, rem_400; 08: 09:! NSLog(@"Enter the year to be tested: "); 10: 11:! scanf("%i", &year); 12: 13:! rem_4 = year % 4; 14:! rem_100 = year % 100; 15:! rem_400 = year % 400; 16: 17:! if( (rem_4 == 0 && rem_100 != 0) || rem_400 == 0 ) 18:! ! NSLog(@"It's a leap year."); 19:! else 20:! ! NSLog(@"Nope, It's not a leap year."); 21: 22:! [pool drain]; 23:! return 0; 24: } Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 10. 10 Nested if Statements if ( [chessGame isOver] == NO ) if ( [chessGame whoseTurn] == YOU ) [chessGame yourMove]; if ( [chessGame isOver] == NO && [chessGame whoseTurn] == YOU ) [chessGame yourMove]; Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 11. 11 Nested if Statements if ( [chessGame isOver] == NO ) if ( [chessGame whoseTurn] == YOU ) [chessGame yourMove]; else [chessGame myMove]; if ( [chessGame isOver] == NO ) if ( [chessGame whoseTurn] == YOU ) [chessGame yourMove]; else [chessGame myMove]; else [chessGame finish]; Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 12. 12 Dangling Else if ( [chessGame isOver] == NO ) if ( [chessGame isOver] == NO ) if ( [chessGame whoseTurn] == YOU ) if ( [chessGame whoseTurn] == YOU ) [chessGame yourMove]; [chessGame yourMove]; else else [chessGame finish]; [chessGame finish]; if ( [chessGame isOver] == NO ) { if ( [chessGame whoseTurn] == YOU ) [chessGame yourMove]; } else [chessGame finish]; Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 13. 13 The else if Construct if ( expression_1 ) if ( expression_1 ) program_statement_1 program_statement_1 else else if ( expression_2 ) if ( expression_2 ) program_statement_2 program_statement_2 else else program_statement_3 program_statement_3 Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 14. 14 The else if Construct Program 6.6 01: #import <Foundation/Foundation.h> 02: 03: int main(int argc, const char * argv[]) 04:{ 05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 06: 07:! int number, sign; 08: 09:! NSLog(@"Please type in a number: "); 10:! scanf("%i", &number); 11: 12:! if (number <0) 13:! ! sign = -1; 14:! else if ( number == 0 ) 15:! ! sign = 0; // Must be positive 16:! else 17:! ! sign = 1; 18:! 19:! NSLog(@"Sign = %i", sign); 20: 21:! [pool drain]; 22:! return 0; 23: Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 15. 15 The else if Construct Program 6.7 01: #import <Foundation/Foundation.h> 02: 03: int main(int argc, const char * argv[]) 04: { 05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 06: 07:! char c; 08: 09:! NSLog(@"Enter a single character: "); 10:! scanf(" %c", &c); 11: 12:! if (( c>= 'a' && c<='z') || (c>='A' && c<='Z')) 13:! ! NSLog(@"It's a alphabetic character."); 14:! else if (c >='0' && c<='9') 15:! ! NSLog(@"It's a digit."); 16:! else 17:! ! NSLog(@"It's a special character."); 18: 19:! [pool drain]; 20:! return 0; 21: } Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 16. 16 The else if Construct Program 6.8, Program 6.8A 01: int main(int argc, const char * argv[]) 02: { 03:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 04:! double! value1, value2; 05:! char! ! operator; 06:! Calculator * deskCalc = [[Calculator alloc] init]; 07:! NSLog(@"Type in your expression. "); 08:! scanf("%lf %c %lf", &value1, & operator, &value2); 09: 10:! [deskCalc setAccumulator: value1]; 11:! if (operator == '+') 11:! ! if (operator == '+') 12:! ! [deskCalc add: value2]; 12:! ! ! [deskCalc add: value2]; 13:! else if (operator == '-') 13:! ! else if (operator == '-') 14:! ! [deskCalc subtract: value2]; 14:! ! ! [deskCalc subtract: value2]; 15:! else if (operator == '*') 15:! ! else if (operator == '*') 16:! ! [deskCalc multiply: value2]; 16:! ! ! [deskCalc multiply: value2]; 17:! else if (operator == '/') 17:! ! else if (operator == '/') 18:! ! [deskCalc divide: value2]; 18:! ! ! if( value2 == 0) 19:! 19:! ! ! ! NSLog(@"Division by zero."); 20:! NSLog(@"%.2f", [deskCalc accumulator]); 20:! ! ! else! 21: 21:! ! ! ! [deskCalc divide: value2]; 22:! [deskCalc release]; 22:! ! else 23:! [pool drain]; 23:! ! ! NSLog(@"Unknown operator."); 24:! return 0; 25: } Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 17. 17 The switch Statement if ( expression == value1) switch ( expression ) { { program statement; case value1: program statement; program statement; … program statement; } … else if ( expression == value2) break; { case value2: program statement; program statement; program statement; program statement; … … } break; else if ( expression == value3) case value3: { program statement; program statement; program statement; program statement; … … break; } default: else program statement; { program statement; program statement; … program statement; break; … } } Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 18. 18 The else if Construct Program 6.8, Program 6.9 03:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 04:! double! value1, value2; 05:! char! ! operator; 06:! Calculator * deskCalc = [[Calculator alloc] init]; 07:! NSLog(@"Type in your expression. "); 08:! scanf("%lf %c %lf", &value1, & operator, &value2); 09: 10:! ! if (operator == '+') 10:! ! switch (operator) { 11:! ! ! [deskCalc add: value2]; 11:! ! ! ! case '+': 12:! ! else if (operator == '-') 12:! ! ! ! ! [deskCalc add: value2]; 13:! ! ! [deskCalc subtract: value2]; 13:! ! ! ! ! break; 14:! ! else if (operator == '*') 14:! ! ! ! case '-': 15:! ! ! [deskCalc multiply: value2]; 15:! ! ! ! ! [deskCalc subtract: value2]; 16:! ! else if (operator == '/') 16:! ! ! ! ! break; 17:! ! ! if( value2 == 0) 17:! ! ! ! case '*': 18:! ! ! ! NSLog(@"Division by zero."); 18:! ! ! ! ! [deskCalc multiply: value2]; 19:! ! ! else! 19:! ! ! ! ! break; 20:! ! ! ! [deskCalc divide: value2]; 20:! ! ! ! case '/': 21:! ! else 21:! ! ! ! ! [deskCalc divide: value2]; 22:! ! ! NSLog(@"Unknown operator.");! 22:! ! ! ! ! break; 23:! NSLog(@"%.2f", [deskCalc accumulator]); 23:! ! ! ! default: 24: 24:! ! ! ! ! NSLog(@"Unknown operator."); 25:! [deskCalc release]; 25:! ! ! } 26:! [pool drain]; Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language
  • 19. 19 Boolean Variable Program 6.10, Program 6.10A 01: #import <Foundation/Foundation.h> 02: 03: int main(int argc, const char * argv[]) 04: { 05:! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 06: 07:! int p, d, isPrime; 08:! 09:! for (p =2; p<=50; ++p){ 08:! BOOL isPrime; 10:! ! isPrime =1; 09:! ! 11:! ! 10:! ! for (p =2; p<=50; ++p){ 12:! ! for ( d = 2; d < p; ++d) 11:! ! ! isPrime = YES; 13:! ! ! if ( p % d == 0) 12:! ! ! 14:! ! ! ! isPrime = 0; 13:! ! ! for ( d = 2; d < p; ++d) 15:! ! ! ! 14:! ! ! ! if ( p % d == 0) 16:! ! if( isPrime != 0 ) 15:! ! ! ! ! isPrime = NO; 17:! ! ! NSLog(@"%i ", p); 16:! ! ! ! ! 18:! } 17:! ! ! if( isPrime == YES ) 19:! 18:! ! ! ! NSLog(@"%i ", p); 20:! [pool drain]; 19:! ! } 21:! return 0; 22: } Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language