I am making a concatenating do-while loop wherein each of the entered strings will be added to the main string $food. Here is the code:
do {
print("\nEnter your order(-1 to end): ");
$order = <>;
chop($order);
if ($order != -1) {
$food .= " ".$order;
print($food);
}
} while ( $order != -1)
print ($food); #PROBLEM HERE!
The problem is that whenever I put print ($food) outside the loop, a syntax error for this line appears plus an Execution of file.pl aborted due to compilation errors message.
The code works once I put print ($food) inside the loop but I am curious to why this error is happening.
Your line before last print has syntax error – it does not end with
;.Just add it and it should work.