nested-loops

Looping over pairs of values in bash

社会主义新天地 提交于 2019-11-25 22:35:47
问题 I have 10 text files and I want to paste each file with its pair, such that I have 5 total files. I tried the following: for i in 4_1 5_1 6_1 7_1 8_1 do for j in 4_2 5_2 6_2 7_2 8_2 do paste ${i}.txt ${j}.txt > ${i}.${j}.txt done done However, this code combines every possible combination instead of just combining the matching pairs. So I would like file 4_1.txt to be paired with 4_2.txt , 5_1.txt with 5_2.txt , etc. 回答1: If you want to use one variable and perform and action with it, you

Can I use break to exit multiple nested for loops?

♀尐吖头ヾ 提交于 2019-11-25 18:42:21
Is it possible to use the break function to exit several nested for loops? If so, how would you go about doing this? Can you also control how many loops the break exits? AFAIK, C++ doesn't support naming loops, like Java and other languages do. You can use a goto, or create a flag value that you use. At the end of each loop check the flag value. If it is set to true, then you can break out of that iteration. No, don't spoil it with a break . This is the last remaining stronghold for the use of goto . Another approach to breaking out of a nested loop is to factor out both loops into a separate