File: while.in

package info (click to toggle)
fish 3.0.2-2%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,448 kB
  • sloc: ansic: 75,559; cpp: 43,314; sh: 9,096; javascript: 7,710; python: 2,538; makefile: 1,461; objc: 709; perl: 367; xml: 18
file content (73 lines) | stat: -rw-r--r-- 1,348 bytes parent folder | download | duplicates (2)
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
# vim: set ft=fish:

function never_runs
	while false
	end
end

function early_return
	while true
		return 2
	end
end

function runs_once
	set -l i 1
	while test $i -ne 0 && set i (math $i - 1)
	end
end

# this should return 1
never_runs; echo "Empty Loop in Function: $status"

# this should return 0
runs_once; echo "Runs Once: $status"

# this should return 2
early_return; echo "Early Return: $status"

logmsg Loops exit status handling

function set_status ; return $argv[1]; end

# The previous status is visible in the loop condition.
# This includes both the incoming status, and the last command in the
# loop body.
set_status 36
while begin
     set -l saved $status
     echo "Condition Status: $status"
     set_status $saved
  end
  true
end

# The condition status IS visible in the loop body.
set_status 55
while true
  echo "Body Status: $status"
  break
end

# The status of the last command is visible in the loop condition
set_status 13
while begin
     set -l saved $status
     echo "Condition 2 Status: $saved"
     test $saved -ne 5
  end
  set_status 5
end

# The status of the last command is visible outside the loop
set rem 5 7 11
while [ (count $rem) -gt 0 ]
  set_status $rem[1]
  set rem $rem[2..-1]
end
echo "Loop Exit Status: $status"

# Empty loops succeed.
false
while false; end
echo "Empty Loop Status: $status"