while-loop

Storing values using if inside while loop BASH

大憨熊 提交于 2020-12-15 05:12:10
问题 I am working with a new script that reads from a log file and then stores the ips which match one of the two patterns: Either its a failed attempt or its a failed attempt using ssh. My code runs good, but the problem is that when the while condition finishes, when I want to call the variable which stores all the IPs it only shows the last one. #!/bin/bash while IFS=";" read -r p || [ -n "$p" ] do first=$(echo $p | sed -E -e "s/[[:blank:]]+/;/g" | cut -d ";" -f 6) if [[ $first == "Failed" ]];

Use the results of a while loop in another while loop

浪子不回头ぞ 提交于 2020-12-13 05:11:36
问题 I'm having big trouble trying to create a while loop within a while loop. The first while loop is supposed to output categories. The second while loop is supposed to output the links associated with the category. The link information is in a links table and the categories information in the category table. I'm trying to do a JOIN on links.catID on category.ID. Links table: id links url catID type Category table: id cat type links.catID is supposed to equal category.id in ints. category.cat

Use the results of a while loop in another while loop

ⅰ亾dé卋堺 提交于 2020-12-13 05:10:10
问题 I'm having big trouble trying to create a while loop within a while loop. The first while loop is supposed to output categories. The second while loop is supposed to output the links associated with the category. The link information is in a links table and the categories information in the category table. I'm trying to do a JOIN on links.catID on category.ID. Links table: id links url catID type Category table: id cat type links.catID is supposed to equal category.id in ints. category.cat

Use the results of a while loop in another while loop

半世苍凉 提交于 2020-12-13 05:10:06
问题 I'm having big trouble trying to create a while loop within a while loop. The first while loop is supposed to output categories. The second while loop is supposed to output the links associated with the category. The link information is in a links table and the categories information in the category table. I'm trying to do a JOIN on links.catID on category.ID. Links table: id links url catID type Category table: id cat type links.catID is supposed to equal category.id in ints. category.cat

beginner Python program using count-based iteration structure

懵懂的女人 提交于 2020-12-09 06:42:53
问题 I am in a beginner Python programming class and we were to write a program that generates an item description, it's price, and the total. The program I originally wrote used LISTS which landed me a fat 0 for the assignment because apparently we were not to use lists on this assignment. Fortunately for me I get to rewrite it. SO, I am supposed to use a count-based iteration structure, I can use the “for” statement, or both the “for” and “while” statements. But NOT just the “while” statement

beginner Python program using count-based iteration structure

心不动则不痛 提交于 2020-12-09 06:42:19
问题 I am in a beginner Python programming class and we were to write a program that generates an item description, it's price, and the total. The program I originally wrote used LISTS which landed me a fat 0 for the assignment because apparently we were not to use lists on this assignment. Fortunately for me I get to rewrite it. SO, I am supposed to use a count-based iteration structure, I can use the “for” statement, or both the “for” and “while” statements. But NOT just the “while” statement

Combining foreach and while in PHP

℡╲_俬逩灬. 提交于 2020-12-05 04:58:12
问题 This seems like it should be a simple question, but I can't find a good answer. Is there a way of putting a condition on a foreach loop? I'd like something like this: foreach ($array as $value WHILE $condition == true) { //do some code } Of course I could just put an if condition inside of the foreach loop as follows: foreach ($array as $value) { if($condition == true) {//do some code} } The only thing is that I'd like to stop iterating over the array once the if condition becomes false, for

Combining foreach and while in PHP

独自空忆成欢 提交于 2020-12-05 04:56:32
问题 This seems like it should be a simple question, but I can't find a good answer. Is there a way of putting a condition on a foreach loop? I'd like something like this: foreach ($array as $value WHILE $condition == true) { //do some code } Of course I could just put an if condition inside of the foreach loop as follows: foreach ($array as $value) { if($condition == true) {//do some code} } The only thing is that I'd like to stop iterating over the array once the if condition becomes false, for

Is using a while block to do nothing a bad thing?

≯℡__Kan透↙ 提交于 2020-11-30 04:22:03
问题 I'm currently working through the excercises in 'The C Programming Language'. Here's one of my solutions: int c; while ((c=getchar()) != EOF) { if (c == ' ') { while ((c = getchar()) == ' ') {} // do nothing? putchar(' '); } putchar(c); } I found some solutions here that are quite different to mine and use an extra variable to keep track of what's going on, whereas I just use a while loop to skip through all the spaces. My solution feels a bit messy, as it seems bit hackish to have a while

Is using a while block to do nothing a bad thing?

ⅰ亾dé卋堺 提交于 2020-11-30 04:20:07
问题 I'm currently working through the excercises in 'The C Programming Language'. Here's one of my solutions: int c; while ((c=getchar()) != EOF) { if (c == ' ') { while ((c = getchar()) == ' ') {} // do nothing? putchar(' '); } putchar(c); } I found some solutions here that are quite different to mine and use an extra variable to keep track of what's going on, whereas I just use a while loop to skip through all the spaces. My solution feels a bit messy, as it seems bit hackish to have a while