foreach

Java Enhanced For Loop

蓝咒 提交于 2021-01-27 06:48:08
问题 How would I write the following for loop using an enhanced for loop> int [] info = {1,2,3,4,5,6,7,8,9,10}; int i; for (i = 0; i < info.length; i++) { if ((i+1) % 10 == 0) System.out.println(info[i]); else System.out.println(info[i] + ", "); } I am trying the following, but i guess im doing it incorreclty for(int i: info){ body here/// 回答1: Your syntax is correct. The difference is only that you're assigning the actual int value to i instead of the loop index. Thus, if you replace (i+1) % 10

Java Enhanced For Loop

主宰稳场 提交于 2021-01-27 06:45:42
问题 How would I write the following for loop using an enhanced for loop> int [] info = {1,2,3,4,5,6,7,8,9,10}; int i; for (i = 0; i < info.length; i++) { if ((i+1) % 10 == 0) System.out.println(info[i]); else System.out.println(info[i] + ", "); } I am trying the following, but i guess im doing it incorreclty for(int i: info){ body here/// 回答1: Your syntax is correct. The difference is only that you're assigning the actual int value to i instead of the loop index. Thus, if you replace (i+1) % 10

PowerShell - Enumerating through a collection and change the collection

ぐ巨炮叔叔 提交于 2021-01-26 08:34:49
问题 How it is posible to fix this script? Yes, I´m changing the collection in the foreach loop and this is the reason for this error. An error occurred while enumerating through a collection: Collection was modified; enumeration operation may not execute.. At C:\Users\user\Documents\PowerShell\ChangeAllListsV2.ps1:47 char:20 + foreach <<<< ($list in $webLists) + CategoryInfo : InvalidOperation: (Microsoft.Share...on+SPEnumerator:SPEnumerator) [], RuntimeException + FullyQualifiedErrorId :

discord.js list all my bot commands

一个人想着一个人 提交于 2021-01-25 04:34:31
问题 i made a discord bot with discord.js and tried to do a help command to show the user all available commands. example command: avatar.js module.exports.run = async(bot, message, args) => { let msg = await message.channel.send("doing some magic ..."); let target = message.mentions.users.first() || message.author; await message.channel.send({files: [ { attachment: target.displayAvatarURL, name: "avatar.png" } ]}); msg.delete(); } module.exports.help = { name: "avatar", description: "show the

discord.js list all my bot commands

匆匆过客 提交于 2021-01-25 04:32:37
问题 i made a discord bot with discord.js and tried to do a help command to show the user all available commands. example command: avatar.js module.exports.run = async(bot, message, args) => { let msg = await message.channel.send("doing some magic ..."); let target = message.mentions.users.first() || message.author; await message.channel.send({files: [ { attachment: target.displayAvatarURL, name: "avatar.png" } ]}); msg.delete(); } module.exports.help = { name: "avatar", description: "show the

pandas set names of dataframes in loop [duplicate]

Deadly 提交于 2021-01-25 03:55:35
问题 This question already has answers here : How to divide the dataframe in pandas into multiple dataframes based on the group by results? (1 answer) Using a string variable as a variable name [duplicate] (3 answers) Closed 2 years ago . I want to create multiple dataframes of names that the same as values in one of the column. I would like this code to work like that: import pandas as pd data=pd.read_csv('athlete_events.csv') Sports = data.Sport.unique() for S in Sports: name=str(S) name=data

pandas set names of dataframes in loop [duplicate]

我的梦境 提交于 2021-01-25 03:54:45
问题 This question already has answers here : How to divide the dataframe in pandas into multiple dataframes based on the group by results? (1 answer) Using a string variable as a variable name [duplicate] (3 answers) Closed 2 years ago . I want to create multiple dataframes of names that the same as values in one of the column. I would like this code to work like that: import pandas as pd data=pd.read_csv('athlete_events.csv') Sports = data.Sport.unique() for S in Sports: name=str(S) name=data

pandas set names of dataframes in loop [duplicate]

好久不见. 提交于 2021-01-25 03:51:39
问题 This question already has answers here : How to divide the dataframe in pandas into multiple dataframes based on the group by results? (1 answer) Using a string variable as a variable name [duplicate] (3 answers) Closed 2 years ago . I want to create multiple dataframes of names that the same as values in one of the column. I would like this code to work like that: import pandas as pd data=pd.read_csv('athlete_events.csv') Sports = data.Sport.unique() for S in Sports: name=str(S) name=data

How to for_each through a list(objects) in Terraform 0.12

会有一股神秘感。 提交于 2021-01-20 16:22:39
问题 I need to deploy a list of GCP compute instances. How do I loop for_each through the "vms" in a list of objects like this: "gcp_zone": "us-central1-a", "image_name": "centos-cloud/centos-7", "vms": [ { "hostname": "test1-srfe", "cpu": 1, "ram": 4, "hdd": 15, "log_drive": 300, "template": "Template-New", "service_types": [ "sql", "db01", "db02" ] }, { "hostname": "test1-second", "cpu": 1, "ram": 4, "hdd": 15, "template": "APPs-Template", "service_types": [ "configs" ] } ] } 回答1: Seem's like I

Javascript square all element in array not working

房东的猫 提交于 2021-01-20 13:55:40
问题 function square(arr) { var result=[].concat(arr); result.forEach(function(i){ i=i*i; console.log(i); }) return result; } var arr=[1,2,3,4]; console.log(square(arr)) The task is to square all elements in an array, now my output is the original array. I wonder why. P.s. the first console.log gives me the output1;4;9;16. the second console.log outputs [1,2,3,4] 回答1: forEach is iterating the array but it is not returning anyvvalue.Use map function which will return a new array with updated result