while

Execute the command list while the specified expression is not zero.

Syntax

GDB Mode:

while expr
commands  
end

IDB Mode:

while expr "{" commands "}"

Parameters

expr

Conditional expression controlling the while-loop

commands

One or more debugger commands or programmatic expressions to be executed.

GDB Mode:

Enter one command per line.

IDB Mode:

Delineate commands with a semicolon (;).

Description

The debugger executes the commands in cmdlist as long as expr evaluates to a non-zero value.

This is different from testing for true or false according to the current language. For example, if the current langauge is Fortran and the expression evaluates to 2, the while continues, because although 2 is .FALSE. in Fortran, 2 is non-zero.

While you can put continue, step or next commands in the while command's body, be aware that doing so may lead to confusion. For example, breakpoints may trigger during a continuation of the application within the body of the while command.

GDB Mode: This command only applies when you are using the debugger in command-line mode. It has no effect when you are using the Console window in the GUI. 

Example

GDB Mode:

(idb) set $loop = 5  
(idb) while $loop > 0  
 >output "$loop is "
 >output $loop
 >echo \n
 >set $loop = $loop - 1
 >end
$loop is 5 
$loop is 4 
$loop is 3 
$loop is 2 
$loop is 1 

IDB Mode:

(idb) while $loop > 0 { p $loop; set $loop = $loop - 1}
5
4
3
2
1
(idb)

The following example demonstrates a more complicated use of the while command, including continuing the application within the body of the while:

IDB Mode:

(idb) run
The list is:
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
167 cout << "Node " << i ;
(idb)
(idb) while (currentNode->_data != 5) { print "currentNode->_data is ",
currentNode->_data; cont }  
currentNode->_data is 1
Node 1 type is integer, value is 1
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
167 cout << "Node " << i ;
currentNode->_data is 2
Node 2 type is compound, value is 12.345
parent type is integer, value is 2
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
167 cout << "Node " << i ;
currentNode->_data is 7
Node 3 type is compound, value is 3.1415
parent type is integer, value is 7
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
167 cout << "Node " << i ;
currentNode->_data is 3
Node 4 type is integer, value is 3
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
167 cout << "Node " << i ;
currentNode->_data is 4
Node 5 type is integer, value is 4
[1] stopped at [void List<Node>::print(void) const:167 0x0804af2e]
167 cout << "Node " << i ;
(idb)
(idb) print currentNode->_data
5

Submit feedback on this help topic

Copyright © 2001-2011, Intel Corporation. All rights reserved.