HP 9g hp 9g_user's manual_manuel de l'utilisateur_EF_HDP1SG181S5.pdf - Page 28

Post-fixed: Memory variable, Memory variable, Pre-fixed, Memory variable, Memory variable, SLEEP

Page 28 highlights

⇒ Each program needs an END command to mark the end of the program. This is displayed automatically when you create a new program. Increment and decrement Post-fixed: Memory variable + + or Memory variable - - Pre-fixed: + + Memory variable or - - Memory variable ⇒ A memory variable is decreased or increased by one. For standard memory variables, the + + ( Increment ) and - - ( Decrement ) operators can be either post-fixed or pre-fixed. For array variables, the operators must be pre-fixed. With pre-fixed operators, the memory variable is computed before the expression is evaluated; with post-fixed operators, the memory variable is computed after the expression is evaluated. For loop FOR ( start condition; continue condition; re-evaluation ) { statements } ⇒ A FOR loop is useful for repeating a set of similar actions while a specified counter is between certain values. For example: FOR ( A = 1 ; A ≤ 4 ; A + + ) { C = 3 × A ; PRINT " ANS = " , C } END ⇒ Result : ANS = 3, ANS = 6, ANS = 9, ANS = 12 The processing in this example is: 1. FOR A = 1: This initializes the value of A to 1. Since A = 1 is consistent with A ≤ 4, the statements are executed and A is incremented by 1. 2. Now A = 2. This is consistent with A ≤ 4, so the statements are executed and A is again incremented by 1. And so on. 3. When A = 5, it is no longer true that A ≤ 4, so statements are not executed. The program then moves on to the next block of code. Sleep command SLEEP ( time ) ⇒ A SLEEP command suspends program execution for a specified time (up to a maximum of 105 seconds). This is useful for displaying intermediate results before resuming execution. Swap command SWAP ( memory variable A, memory variable B ) E-28

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172

E-28
Each program needs an
END
command to mark the end of the
program. This is displayed automatically when you create a new
program.
Increment and decrement
Post-fixed: Memory variable + +
or
Memory variable – –
Pre-fixed: +
+ Memory variable
or
– – Memory variable
A memory variable is decreased or increased by one. For standard
memory variables, the
+ +
( Increment ) and
– –
( Decrement ) operators
can be either post-fixed or pre-fixed. For array variables, the operators
must be pre-fixed.
With pre-fixed operators, the memory variable is computed before the
expression is evaluated; with post-fixed operators, the memory variable
is computed after the expression is evaluated.
For loop
FOR
(
start condition; continue condition; re-evaluation
) {
statements
}
A
FOR
loop is useful for repeating a set of similar actions while a
specified counter is between certain values.
For example:
FOR
( A = 1 ; A
4 ; A + + )
{ C = 3
×
A ; PRINT
ANS =
, C }
END
Result : ANS = 3, ANS = 6, ANS = 9, ANS = 12
The processing in this example is:
1.
FOR
A = 1
: This initializes the value of
A
to
1
. Since
A = 1
is consistent
with
A
4
, the
statements
are executed and
A
is incremented by 1.
2. Now
A = 2
. This is consistent with
A
4
, so the
statements
are
executed and
A
is again incremented by 1. And so on.
3. When
A = 5
, it is no longer true that
A
4
, so
statements
are not
executed. The program then moves on to the next block of code.
Sleep command
SLEEP (
time
)
A
SLEEP
command suspends program execution for a specified time
(up to a maximum of 105 seconds). This is useful for displaying
intermediate results before resuming execution.
Swap command
SWAP (
memory variable A, memory variable B
)